﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using System.IO;
using System.Text;

namespace PeisongWeb.admin
{
    public partial class exportData :adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("ED", 1))
                {
                    rootCategoryBind();
                    ddlBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }

        private void rootCategoryBind()
        {
            DataTable dt = logic.category.getByParent(0);
            ddl_CategoryRoot.DataSource = dt;
            ddl_CategoryRoot.DataBind();
            ddl_CategoryRoot.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--请选择--", "0"));
            ddl_CategorySub.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--请选择--", "0"));
        }

        private void subCategoryBind()
        {
            //当大类不等于空的时候，就绑定小类
            if (ddl_CategoryRoot.SelectedValue != "0")
            {
                DataTable dt = logic.category.getByParent(Convert.ToInt32(ddl_CategoryRoot.SelectedValue));
                ddl_CategorySub.DataSource = dt;
                ddl_CategorySub.DataBind();
                ddl_CategorySub.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--请选择--", "0"));
            }
            else
            {
                ddl_CategorySub.Items.Clear();
                ddl_CategorySub.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--请选择--", "0"));
            }
        }
        protected void ddl_CategoryRoot_SelectedIndexChanged(object sender, EventArgs e)
        {
            subCategoryBind();
        }

        // 导出商品的采购量、总进价、总出价
        protected void lbl_ExportToExcel_Click(object sender, EventArgs e)
        {
            int parentid = Convert.ToInt32(ddl_CategoryRoot.SelectedValue);
            int categoryid = Convert.ToInt32(ddl_CategorySub.SelectedValue);
            string productno = txt_ProductNo.Text.Trim();
            string productname = txt_ProductName.Text.Trim();
            DateTime? startDate = null;
            DateTime? endDate = null;

            if (ext_StartInputDt.SelectedDate != DateTime.MinValue)
                startDate = ext_StartInputDt.SelectedDate;
            if (ext_EndInputDt.SelectedDate != DateTime.MinValue)
                endDate = ext_EndInputDt.SelectedDate;

            // 查询数据
            DataTable dt = logic.orderItem.listWithPurchaseInfo(parentid, categoryid, productno, productname, startDate, endDate);

            // 导出Excel
        }

        private void ddlBind()
        {
            DataTable dt = logic.company.listWithCompanyType("1");
            ddl_seller.DataSource = dt;
            ddl_seller.DataBind();
        }

        /// <summary>
        /// 导出供应商所供应的商品
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbn_ExportProduct_Click(object sender, EventArgs e)
        {
            int sellerid = Convert.ToInt32(ddl_seller.SelectedValue);

            // 查询数据
            DataTable dt = logic.sellerRange.getByCompanyId(sellerid);
            String xlsName = logic.company.getById(sellerid).Company+"供应的商品";

            //
        }
    }
}
